<template>
	<view class="contents" :style="'height:'+screenHeight+'px;'">
		<view class="bodys">
			<view class="none" v-if="show">
				<view class="coent">
					<u-empty text="您已提交过满意度评价" mode="list" icon-size="200">
					</u-empty>
				</view>
			</view>
			<view class="conent" v-else>
				<view class="header">
					<view style="text-align: center;">集宁区妇幼保健计划生育服务中心</view>
					<view style="text-align: center;">就诊人员满意度调查</view>
				</view>
				<view class="neiorng">
					<!-- 	<view class="">
						一、个人基本信息
					</view> -->

					<view class="datalist" v-for="(item,index) in datalist2" :key="index">

						<view class="list">
							<span style="color: red;">*&nbsp;</span>
							<!-- <span style="font-weight: bold;">{{item.ProTempCode}}.&nbsp;</span> -->

							<span style="margin-left: 3%;">{{item.ProTemContent}}</span>
						</view>

						<view class="listb">

							<u-radio-group v-model="item.value" iconPlacement="left">

								<u-radio v-for="(itema, indexa) in item.lists" @change="radioGroupChange2"
									label-size="14px" :key="indexa" :name="itema.name">

									{{itema.name}}
								</u-radio>
							</u-radio-group>

						</view>
						<text v-if="!item.value" class="error-tip">
							请选择{{item.ProTem}}!
						</text>

					</view>
				</view>



				<u-form-item label="性别" prop="sex" label-width="140">
					<u-input v-model="userInfo.sex" placeholder="请选择性别" type="select" @click="select1.show=true" />

				</u-form-item>
				<text v-if="!userInfo.sex" class="error-tip">
					请选择性别!
				</text>
				<u-form-item label="年龄" prop="age" label-width="140">
					<u-input placeholder="请填写年龄" :maxlength="2" v-model="userInfo.age" />

				</u-form-item>
				<text v-if="!userInfo.age" class="error-tip">
					请填写年龄!
				</text>


				<!-- <view class="" style="display: flex;align-items: center;">
					性别
					<u-input v-model="xingbie"  placeholder="请选择性别" type="select" @click="select1.show=true" />
				</view>
					
			
				<u-field required v-model="age" label="年龄" type="number"   placeholder="请填写年龄" :error-message="age == '' ? '请填写年龄！' : ''">
				</u-field> -->
				<view class="neiorng">
					<view class="datalist" v-for="(item,index) in datalist" :key="index">
						<view class="list">
							<span style="color: red;">*&nbsp;</span>
							<span style="font-weight: bold;">{{item.ProTempCode}}.&nbsp;</span>
							<span>{{item.ProTemContent}}</span>
						</view>
						<!-- @tap="ssss(index)" -->
						<view class="listb">
							<u-radio-group v-model="wjtx[index].value">
								<u-radio v-for="(itema, indexa) in wjtx[index].lists" @change="radioGroupChange"
									:key="indexa" :name="itema.name">
									{{itema.name}}
								</u-radio>
							</u-radio-group>
						</view>
					</view>
					<view class="jianyi">
						<view style="margin-bottom: 10rpx;">请填写您对院内整体服务的意见或建议:</view>
						<u-input v-model="jianyival" border type="textarea" />
					</view>

					<view class="jianyi">
						<view style="margin-bottom: 10rpx;">注：若您愿意与我们进一步沟通，请您填写一下信息，我们尽快回复您并落实您的相关意见或建议：
						</view>
						<u-field v-model="name" labelWidth="230" label="姓名（先生/女士）" placeholder="请填写姓名">
						</u-field>
						<u-field v-model="phone" type="number" label="联系电话" placeholder="请填写电话">

						</u-field>

					</view>

					<view style="width: 100%;display: flex;justify-content: center;padding:40rpx;">
						<view class="submit">
							<u-button type="primary" @click="submit">提交</u-button>
						</view>
					</view>
				</view>

			</view>

		</view>
		<u-select v-model="select1.show" :list="select1.list" @confirm="onSelect1"></u-select>
	</view>
</template>

<script>
	export default {
		data() {
			return {

				name: '',
				occupation: '',
				phone: '',
				xingbie: "",
				age: '',
				show: true,
				jianyival: '',
				screenHeight: getApp().globalData.screenHeight - 44,
				datalist: '',
				wjtx: [],
				text: '',
				select1: {
					show: false,
					current: {},
					list: [{
							value: 1,
							label: '男'
						},
						{
							value: 2,
							label: '女'
						}
					],
				},
				rules: {
					sex: [{
						required: true,
						message: '请选择性别',
						trigger: ['blur', 'change']
					}],
					age: [{
						required: true,
						message: '请输入年龄',
						trigger: ['blur', 'change']
					}]
				},
				userInfo: {
					sex: '',
					age: '',
				},
				datalist2: [{
						// ProTempCode: 1,
						ProTem: "就诊科室",
						ProTemContent: "就诊科室：",
						lists: [{
								name: '儿科',
								//	disabled: false,
							},
							{
								name: '中医儿科',
								//	disabled: false,
							},
							{
								name: '儿保科',
								//	disabled: false,
							},
							{
								name: '妇保科',
								//	disabled: false,
							},
							{
								name: '妇科',
								//	disabled: false,
							},
							{
								name: '婚检科',
								//	disabled: false,
							},

						],

						value: ""

					},
					{
						// ProTempCode: 1,
						ProTem: "挂号方式",
						ProTemContent: "您今天是挂号方式？",
						lists: [{
								name: '微信公众号预约',
								//	disabled: false,
							},
							{
								name: '人工电话预约',
								//	disabled: false,
							},
							{
								name: '现场挂号',
								//	disabled: false,
							},


						],

						value: ""

					},
				],
			}
		},

		onLoad() {
			this.list()
		},
		
		methods: {



			ssss(index) {
				console.log("满意度问题", index)
				if (this.text != '') {
					this.wjtx[index].value = this.text
				}
				console.log("wjtx", this.wjtx)
			},
			pinkProDetails() {
				console.log(this.wjtx)
				console.log(this.datalist)
				let temp3 = {
					prodetail: ''

				}
				let temp = []

				// let temp = `{"prodetail":[`
				for (let i = 0; i < this.wjtx.length; i++) {

					let le
					switch (this.wjtx[i].value) {
						case '非常满意':
							le = 10;
							break
						case '满意':
							le = 8;
							break
						case '一般':
							le = 6;
							break
						case '不满意':
							le = 0;
							break
					}

					temp.push({
						ProTempId: this.datalist[i].ProTempId,
						PF: le
					});





				}
				console.log(temp)
				temp3.prodetail = temp
				// temp = temp + `]}`

				return JSON.stringify(temp3)

			},
			onSelect1(arr) {
				let current = arr[0];
				console.log("current", current)
				let label = current.label;
				this.select1.current = current;
				this.userInfo.sex = label;
				console.log("this.userInfo.sex", this.userInfo.sex)
			},
			submit() {



			
				if (this.datalist2[0].value == '') {
					uni.showToast({
						title: "请选择就诊科室！",
						icon: 'none',
						duration: 2000
					});
					return


				} else if (this.datalist2[1].value == '') {
					uni.showToast({
						title: "请选择挂号方式！",
						icon: 'none',
						duration: 2000
					});
					return


				} else if (this.userInfo.sex == '') {
					uni.showToast({
						title: "请选择性别！",
						icon: 'none',
						duration: 2000
					});
					return


				} else if (this.userInfo.age == '') {
					uni.showToast({
						title: "请填写年龄！",
						icon: 'none',
						duration: 2000
					});
					return

				}



				uni.showLoading({
					title: '请稍后',
					mask: true
				});
				let sum = 0
				let item = this.wjtx
				console.log(this.wjtx)
				for (let i = 0; i < item.length; i++) {
					if (item[i].value == '非常满意') {
						sum += 10
					} else if (item[i].value == '满意') {
						sum += 8
					} else if (item[i].value == '一般') {
						sum += 6
					} else {
						sum += 0
					}
				}


				let ProDetails = this.pinkProDetails();
				// console.log(this.jianyival,ProDetails,sum,this.name,this.datalist2[0].value,this.datalist2[1].value)
				// console.log("总分", sum)
				//  return
				this.$request("ProblemTem", "Submit", {
					SmType: this.datalist2[1].value,
					Content: this.jianyival,
					ProDetails: ProDetails,
					ZPF: sum,
					Name: this.name,
					Dpt: this.datalist2[0].value,
					Sex: this.userInfo.sex,
					Nl: this.userInfo.age,
					Phone: this.phone,
					Work: "",
					Protype: 1

				}).then(res => {
					console.log("提交满意度问题", res)
					if (res.code == 1) {
						this.show = true
						uni.hideLoading();

					} else {
						uni.hideLoading();
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 2000
						});
					}
				}).catch(err => {
					uni.hideLoading();
					console.log("err", err)
					uni.showToast({
						title: err,
						icon: 'none',
						duration: 1000
					});
				});
			},
			radioChange(e) {
				console.log(e);
			},
			// 选中任一radio时，由radio-group触发
			radioGroupChange(e) {
				console.log(e);
				this.text = e
				console.log("wsat", this.wjtx)

			},
			list() {
				uni.showLoading({
					title: '请稍后',
					mask: true
				});
				this.$request("ProblemTem", "list", {
					protype: 1


				}).then(res => {
					// console.log("满意度问题", res)
					if (res.code == 1) {
						this.datalist = res.data
						this.wjtx = []
						let objet = {
							lists: [{
									name: '非常满意',
									value: 10
								},
								{
									name: '满意',
									value: 8
								},
								{
									name: '一般',
									value: 6
								}, {
									name: '不满意',
									value: 0
								},
							],
							value: '非常满意'
						}
						for (let i = 0; i < res.data.length; i++) {
							this.wjtx[i] = JSON.parse(JSON.stringify(objet))
						}
						console.log("this.wjtx", this.wjtx)
						console.log("this.datalist", this.datalist)
						this.show = false
						uni.hideLoading();

					} else {
						this.show = true
						uni.hideLoading();
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 2000
						});
					}
				}).catch(err => {
					this.show = true
					uni.hideLoading();
					console.log("err", err)
					uni.showToast({
						title: err,
						icon: 'none',
						duration: 1000
					});
				});
			}
		}
	}
</script>

<style>
	@import './myddc.css';
</style>